package com.zw.javaClass;

import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Component;

import com.zw.entity.Commodity;

@Component
public class Test2 {

	
	public List<Commodity> loadScoreInfo(FileInputStream fileIn) throws IOException{
		List<Commodity> temp = new ArrayList<Commodity>();
		//根据指定的文件输入流导入Excel从而产生Workbook对象
		Workbook wb0 = new XSSFWorkbook(fileIn);
		//获取Excel文档中的第一个表单
		Sheet sht0 = wb0.getSheetAt(0);
		//对Sheet中的每一行进行迭代
		for (Row r : sht0) {
			//如果当前行的行号（从0开始）未达到2（第三行）则从新循环
			if(r.getRowNum()<1){
				continue;
			}
			//创建实体类
			Commodity info=new Commodity();
			//取出当前行第1个单元格数据，并封装在info实体stuName属性上
			info.setCommodityname(r.getCell(1).getStringCellValue());
			info.setCommoditycount((int)r.getCell(2).getNumericCellValue());
			info.setCommodityprice(BigDecimal.valueOf(r.getCell(3).getNumericCellValue()));
			info.setCommoditytypeid((int)r.getCell(4).getNumericCellValue());
			temp.add(info);
		}
		fileIn.close();    
		return temp;    
	}
}
